home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / pcl4c341.zip / TERM_IO.C < prev    next >
Text File  |  1992-12-24  |  3KB  |  120 lines

  1. /*** TERM_IO.C ***/
  2.  
  3. #include <stdio.h>
  4. #include "pcl4c.h"
  5. #include "term.h"
  6. #include "ascii.h"
  7.  
  8. /*** Display status line ***/
  9.  
  10. #define INVERSE 0x70
  11. #define RIGHTMOST 40
  12.  
  13. void DisplayLine(MsgPtr,UserPtr,UserLength)
  14. char *MsgPtr;
  15. char *UserPtr;
  16. int UserLength;
  17. {static int right = RIGHTMOST;
  18.  int row;
  19.  int col;
  20.  int i;
  21.  char c;
  22.  int MsgLength;
  23.  row = GetRow();
  24.  col = GetCol();
  25.  Position(24,0);
  26.  /* display message */
  27.  MsgLength = strlen(MsgPtr);
  28.  for(i=0;i<MsgLength;i++)
  29.      {AttrWrite(*MsgPtr++,INVERSE);
  30.       Position(24,i+1);
  31.      }
  32.  /* blank rest of menu bar */
  33.  for(i=MsgLength;i<right;i++)
  34.      {AttrWrite(' ',INVERSE);
  35.       Position(24,i+1);
  36.      }
  37.  right = MsgLength;
  38.  /* want response from user ? */
  39.  if(UserPtr!=NULL)
  40.      {right = RIGHTMOST;
  41.       /* input text from user */
  42.       i = 0;
  43.       while(1)
  44.           {Position(24,MsgLength+i);
  45.            c = SioKeyRead();
  46.            if((c==ESC)||(c==CAN))
  47.                {UserPtr[0] = '\0';
  48.                 break;
  49.                }
  50.            if((c=='\r')||(MsgLength+i==RIGHTMOST))
  51.                {UserPtr[i] = '\0';
  52.                 break;
  53.                }
  54.            if((c==BS)&&(i>0))
  55.                {i--;
  56.                 Position(24,MsgLength+i);
  57.                 AttrWrite(' ',INVERSE);
  58.                }
  59.            else
  60.                {/* save character & display on status line */
  61.                 UserPtr[i++] = c;
  62.                 AttrWrite(c,INVERSE);
  63.                 if(i==UserLength)
  64.                     {/* user string done */
  65.                      UserPtr[i] = '\0';
  66.                      break;
  67.                     }
  68.                }
  69.           } /* end -- while */
  70.      } /* end -- if */
  71.  Position(row,col);
  72. }
  73.  
  74. /*** output character to serial port ***/
  75.  
  76. int PutChar(Port,ch)
  77. int Port;
  78. char ch;
  79. {int rc;
  80.  /* transmit character */
  81.  rc = SioPutc(Port,ch);
  82.  if(rc<0)
  83.      {printf("SioPutc Error: COM%d: ",1+Port);
  84.       SioError(rc);
  85.       SioDone(Port);
  86.       exit(1);
  87.      }
  88.  return(rc);
  89. }
  90.  
  91. /*** receive character from serial port ***/
  92.  
  93. int GetChar(Port,Timeout)
  94. int Port;
  95. int Timeout;
  96. {int rc;
  97.  rc = SioGetc(Port,Timeout);
  98.  if(rc<-1)
  99.      {printf("SioGetc Error: COM%d: ",1+Port);
  100.       SioError(rc);
  101.       exit(1);
  102.      }
  103.  return(rc);
  104. }
  105.  
  106. /*** display the error text ***/
  107.  
  108. void SayError(Port,ptr)
  109. int Port;
  110. char *ptr;
  111. {char temp[81];
  112.  sprintf(temp,"ERROR! COM%d : %s",1+Port,ptr);
  113.  DisplayLine(temp,NULL,0);
  114.  printf("\n*** %s\n",temp);
  115.  /* cancel remote */
  116.  PutChar(Port,CAN);
  117.  PutChar(Port,CAN);
  118.  PutChar(Port,CAN);
  119. } /* end SayError */
  120.